﻿<!--
    Copyright (C) 2011 Ari Rokosa, Chinedu Eze, Johannes Virtanen,
                       Petri Tuononen, Timo Korkalainen

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
-->
@{Layout = null;}

<script type="text/javascript">
    $('#dialog-background').show();
</script>

<div id="dialog-large" class="dialog">
    <div class="close-dialog button-small" onclick="removeEditors();"></div>
    <h2>User settings</h2>

    <div>
        <div class="login-info"><span>Username: </span><input type="text" class = "login-input" id="user"/></div>
        <div class="login-info"><span>Password: </span><input type="password" class = "login-input" id="pass"/></div>
        <div class="login-info"><span>Password: </span><input type="password" class = "login-input" id="pass2"/></div>
        <input class="login-button text-button" id="create" type="submit" value="Create" />
        <input class="login-button text-button" id="delete" type="submit" value="Delete" />
        <script type="text/javascript">
            $('#create').click(function () {
                if (new String(document.getElementById("user").value).length > 2) {
                    if (document.getElementById("pass").value == document.getElementById("pass2").value) {
                        if (new String(document.getElementById("pass").value).length > 4) {
                            $.post("User/AddNewUserToDb?userName=" + document.getElementById("user").value
                            + "&passWord=" + document.getElementById("pass").value, function () {
                                $('#dialog-large').remove();
                                $('#dialog-background').hide();
                            });
                        }
                        else {
                            alert('Password must be longer than 4 symbols');
                        }
                    }
                    else {
                        alert('Password fields do not match.');
                    }
                }
                else {
                    alert('User name must be longer than 2 symbols');
                }
            });
            $('#delete').click(function () {
                $.post("User/DeleteUser?userName=" + document.getElementById("user").value, function () {
                    $('#dialog-large').remove();
                    $('#dialog-background').hide();
                });
            });
       </script>
    </div>

@Ajax.ActionLink("Log out", "Logout", "User", new AjaxOptions { UpdateTargetId = "site-container",
    InsertionMode = InsertionMode.Replace, HttpMethod = "post", OnSuccess = "removeEditors" },
    new { @class = "logout-button text-button" })

</div>